<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="chrome=IE8">
		<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
		<script>
			window.onload = function() {
				arr = [{
					x : 10,
					y : 10,
					width : 100,
					height : 100
				}, {
					x : 110,
					y : 110,
					width : 100,
					height : 100
				}];
				cvs = document.getElementById('animation_canvas');
				ctx = cvs.getContext('2d');
				draw();
				function draw(p) {
					var who = [];
					ctx.clearRect(0, 0, cvs.width, cvs.height);
					arr.forEach(function(v, i) {
						ctx.beginPath();
						ctx.rect(v.x, v.y, v.width, v.height);
						ctx.stroke();
						if (p && ctx.isPointInPath(p.x, p.y)) {
							alert(1);
							who.push(i);
						}
					});
					return who;
				}


				cvs.addEventListener('click', function(e) {
					p = getEventPosition(e);
					draw(p);
				}, false);

				function getEventPosition(ev) {
					return {
						x : ev.offsetX || ev.layerX,
						y : ev.offsetY || ev.layerY
					};
				}

			}
		</script>
	</head>
	<body>
		<canvas id="animation_canvas" width="500" height="500"></canvas>
	</body>
</html>